package com.shuangti.community.service.impl;

import com.shuangti.community.entity.CommunityPostTbl;
import com.shuangti.community.mapper.CommunityPostMapper;
import com.shuangti.community.service.CommunityPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class CommunityPostServiceImpl implements CommunityPostService {

    private final CommunityPostMapper communityPostMapper;

    public CommunityPostServiceImpl(CommunityPostMapper communityPostMapper){
        this.communityPostMapper = communityPostMapper;
    }


    /**
     * 根据用户id获取相应的评论
     *
     * @param user_id 用户id
     * @param page 第几页
     * @param count 多少条
     * @return 记录列表
     */
    @Override
    public List<CommunityPostTbl> getPostsByUserId(Integer user_id, Integer page, Integer count) {
        return communityPostMapper.selectPostsById(user_id,page,count);
    }

    /**
     * 插入评论
     *
     * @param communityPostTbl 一条评论
     * @return 插入评论个数
     */
    @Override
    public int addPost(CommunityPostTbl communityPostTbl) {
        communityPostTbl.setCreatedAt(LocalDateTime.now());
        communityPostTbl.setUpdatedAt(LocalDateTime.now());
        return communityPostMapper.insert(communityPostTbl);
    }


    /**
     * 根据评论id 删除一条评论
     * @param post_id 评论id
     * @return 删除个数
     */
    @Override
    public int delPost(Long post_id) {
        return communityPostMapper.deleteById(post_id);
    }


}
